#include "CSalesman.h"
#include <iostream>
#include <vector>
#include <ctime>

using namespace std;

int N, M, r1, r2;

const double dPi = 6.2831;

vector< Vertex > GetRandGraf()
{
	vector< Vertex > graf( N * M );

	srand( time( NULL ) );

    vector< Vertex > centers( N );

    for( int i = 0; i < N; ++i )
	{
        double d1 = 1.0 - ( double )( rand() ) / ( RAND_MAX + 1 );
		double d2 = 1.0 - ( double )( rand() ) / ( RAND_MAX + 1 );
        double _cos = cos( dPi * d1 );
		double _sin = sin( dPi * d1 );

        centers[i].x = d2 * r1 * _cos;
        centers[i].y = d2 * r1 * _sin;
    }
    for( int i = 0; i < N; ++i )
	{
        for( int j = 0; j < M; ++j )
		{
            double d1 = 1.0 - ( double )( rand() ) / ( RAND_MAX + 1 );
			double d2 = 1.0 - ( double )( rand() ) / ( RAND_MAX + 1 );
            double _cos = cos( dPi * d1 );
			double _sin = sin( dPi * d1 );

			graf[i * M + j].number = i * M + j;
            graf[i * M + j].x = d2 * r2 * _cos + centers[i].x;
            graf[i * M + j].y = d2 * r2 * _sin + centers[i].y;
        }
    }
	return graf;
}

void main()
{

	cout << "Enter number of centers: ";
	cin >> N;

	cout << "Enter number of points per center: ";
	cin >> M;

	cout << "Enter ranges of spread (2 ranges): ";
	cin >> r1;
	cin >> r2;
/*
	N = 5;
	M = 2;
	r1 = 5;
	r2 = 5;
*/
	vector< Vertex > graf = GetRandGraf();
	CSalesman a;
	vector< Vertex* > way;
	cout << "Salesman had to go " << a.Salesman( graf, way, false ) << " kilometers, with Prima algorithm\n";
	cout << "Salesman had to go " << a.Salesman( graf, way, true ) << " kilometers, with Cruskal algorithm\n";
}